package org.edu.controller;

import java.util.Date;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;
import org.edu.bean.TmBizopen;
import org.edu.service.TmBizopenService;

import com.opensymphony.xwork2.ActionSupport;
/**
 * 税务登记查询
 * @author lzh
 *
 * 2012-4-9
 */
@SuppressWarnings("serial")
public class TmTaxRegistQueryController extends ActionSupport {
	@Resource
	private TmBizopenService tmBizopenService;
	private String condition;
	private String conditionValue;
	private Date startdate;
	private Date enddate;
	private Integer id;
	
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getConditionValue() {
		return conditionValue;
	}
	public void setConditionValue(String conditionValue) {
		this.conditionValue = conditionValue;
	}
	public String getCondition() {
		return condition;
	}
	public void setCondition(String condition) {
		this.condition = condition;
	}
	public Date getStartdate() {
		return startdate;
	}
	public void setStartdate(Date startdate) {
		this.startdate = startdate;
	}
	public Date getEnddate() {
		return enddate;
	}
	public void setEnddate(Date enddate) {
		this.enddate = enddate;
	}
	public String input() throws Exception {
		return INPUT;
	}
	public String queryView() throws Exception {
		return "queryView";
	}
	public String queryByCondtion() throws Exception {
		String hql = "";
		Object obj = null;
		if(id != null && id > 0){
			hql = "o.id=?";
			obj = id;
		}else{
			if("按开业登记证号查询".equals(condition)){
				hql = "o.regno=?";
			}else if("按纳税人名称查询".equals(condition)){
				hql = "o.taxplayer=?";
			}else if("按证件号码查询".equals(condition)){
				hql = "o.cardno=?";
			}else if("按法定代表姓名查询".equals(condition)){
				hql = "o.represent=?";
			}
			if(conditionValue != null) obj = conditionValue.trim();
		}
		
		TmBizopen entity = tmBizopenService.findByCondition(hql,obj);
		if(entity == null){
			this.addActionMessage(condition + "在系统中不存在");
			return "message";
		}
		ServletActionContext.getRequest().setAttribute("entity",entity);
		return "detail";
	}
	public String queryByOpenDate() throws Exception {
		ServletActionContext.getRequest()
		.setAttribute("list",tmBizopenService.findByOpenDate(startdate, enddate));
		return "list"; 
	}
	
}
